package com.itheima.功能流.转码流;

import java.io.*;

public class 指定编码读写 {
    public static void main(String[] args) throws Exception {
        File file = new File("day13_IO流_功能流\\a.txt");
        File file1 = new File("day13_IO流_功能流\\b.txt");
        method1(file, file1);



    }
    private static void method2(File file, File file1) throws IOException {
        //创建输入输出流对象
        BufferedReader br = new BufferedReader(new InputStreamReader((new FileInputStream(file)),"utf-8"));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1),"gbk"));

        //定义中间量
        int b;
        char[] chars = new char[1024];
        int len;

        //循环读写
        while ((len = br.read(chars)) != -1){
            bw.write(chars,0,len);
        }

        //关流释放资源
        bw.close();
        br.close();
    }

    private static void method1(File file, File file1) throws IOException {
        //创建输入输出流对象
        InputStreamReader isr = new InputStreamReader((new FileInputStream(file)),"utf-8");
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file1),"gbk");

        //定义中间量
        int b;
        char[] chars = new char[1024];
        int len;

        //循环读写
        while ((len = isr.read(chars)) != -1){
            osw.write(chars,0,len);
        }

        //关流释放资源
        osw.close();
        isr.close();
    }
}
